package com.business.exam.controller;

import com.business.common.core.controller.BaseController;
import com.business.common.core.domain.AjaxResult;
import com.business.common.core.domain.entity.SysDept;
import com.business.common.core.domain.entity.SysUser;
import com.business.common.core.page.TableDataInfo;
import com.business.exam.domain.ExamPaperModel;
import com.business.exam.domain.exam.ExamManageModel;
import com.business.exam.domain.exam.ExamManageUserModel;
import com.business.exam.domain.exam.ExamPaperEditRequestVM;
import com.business.exam.service.IExamManageService;
import com.business.exam.service.IExamPaperService;
import com.business.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


@RestController("AdminExamManageController")
@RequestMapping(value = "/api/admin/exam/manage")
public class ExamManageController extends BaseController {

    @Autowired
    private IExamManageService service;

    @Autowired
    private ISysDeptService deptService;
     /**
     * 新增/修改信息
     */
    @PostMapping(value = "/saveOrEdit")
    public AjaxResult saveOrEdit(@RequestBody ExamManageModel dto) {
        // 存储数据
        service.saveOrEdit(dto);
        return AjaxResult.success("操作成功!");
    }


    /**
     * 查询工程信息列表
     */
    @RequestMapping(value = "/findPageList")
    public TableDataInfo findPageList(ExamManageModel dto) {
        // 开始分页
        startPage();
        List<ExamManageModel> list = service.findPage(dto);
        return getDataTable(list);
    }


    /**
     * 根据ID查询工程信息
     */
    @PostMapping(value = "/findById")
    public AjaxResult findById(@RequestBody ExamManageModel dto) {
        // 存储数据
        ExamManageModel resultData = service.findById(dto);
        return AjaxResult.success("操作成功!", resultData);
    }


    /**
     * 获取对应角色部门树列表
     */
    @GetMapping(value = "/deptTree/{roleId}")
    public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
    {
        AjaxResult ajax = AjaxResult.success();
       // ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
        ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
        return ajax;
    }


    /**
     * 根据部门ID查询人员信息
     */
    @PostMapping(value = "/findSysUserByDeptId")
    public AjaxResult findSysUserByDeptId(@RequestBody String deptIds) {

        // 存储数据
        List<SysUser> resultData = service.findSysUserByDeptId(Arrays.asList(deptIds.split(",")));
        return AjaxResult.success("操作成功!", resultData);
    }

    /**
     * 查询考试参与人员
     */
    @PostMapping(value = "/findExamUsers")
    public AjaxResult findExamUsers(@RequestBody ExamManageUserModel dto) {

        // 存储数据
        List<SysUser> resultData = service.findExamUserList(dto);
        return AjaxResult.success("操作成功!", resultData);
    }


    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    public AjaxResult select(@PathVariable Long id) {
        service.logicDelete(id);
        return AjaxResult.success("操作成功!");
    }

}
